package xddq

import (
	"fmt"
	"time"
	D "websocket_apn/define"
	"websocket_apn/log"
	"websocket_apn/proto"
)

// 处理查看妖盟乱斗信息
func (xd *XdDriver) CheckUnionBattleMatchInfoData(info D.UnionBattleMatchInfo) {
	if len(info.PeopleInfo) == 0 {
		return
	}
	if info.AlreadyMatch {
		time.Sleep(3 * time.Second)
		log.Infof("妖盟乱斗-查看妖盟乱斗信息")
		xd.Send(proto.Get_Cmd_Data(xd.userInfo.PlayerId, proto.S_UNION_BATTLE_ENTER, "08 "+xd.UserData.Activity[D.Activity_UNION_BATTLE].ID))
		return
	}
	if info.NotBuy {
		log.Infof("妖盟乱斗-购买免费增幅20%")
		//购买基础属性 00 +20 01 +50 02 +100
		xd.Send(proto.Get_Cmd_Data(xd.userInfo.PlayerId, proto.S_UNION_BATTLE_BUY_BUFF, "08 "+xd.UserData.Activity[D.Activity_UNION_BATTLE].ID+" 10 00"))
		xd.Send(proto.Get_Cmd_Data(xd.userInfo.PlayerId, proto.S_UNION_BATTLE_CHALLENGE, "08 "+xd.UserData.Activity[D.Activity_UNION_BATTLE].ID+" 10 00"))
	}

	for num, people := range info.PeopleInfo {
		if num == 2 || (people.CombatValue/10000)*5 < (info.SelfCombatValue/10000)*4 {
			time.Sleep(3 * time.Second)
			log.Infof("妖盟乱斗-当前攻击力%s 开始攻击妖盟【%s】成员[%s] 妖力:%s", D.GetCombatValueDesc(info.SelfCombatValue), info.Name, people.Name,
				D.GetCombatValueDesc(people.CombatValue))
			xd.Send(proto.Get_Cmd_Data(xd.userInfo.PlayerId, proto.S_UNION_BATTLE_CHALLENGE, fmt.Sprintf("08 %s 10 %s", xd.UserData.Activity[D.Activity_UNION_BATTLE].ID, people.ID)))
			break
		}
	}
}
